{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'indices'|trans }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'indices'|trans}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/index/index_tabs.html.twig' with {'active': 'list'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.form({'form': form, 'type': 'search'}) }}
        {% endblock %}
    {% endembed %}

    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'list'|trans, 'badge': {'title': indices.total}}) }}

            {% if 0 < indices.total %}
                {% embed 'Embed/buttons_embed.html.twig' %}
                    {% import 'Import/app_import.html.twig' as appImport %}
                    {% block content %}
                        {% if true == hasFeature('force_merge') %}
                            {% if is_granted('INDICES_FORCE_MERGE', 'index') %}
                                {{ appImport.buttonModal({
                                    'id': 'IndicesForceMergeAll',
                                    'title': 'force_merge'|trans,
                                    'badge': {'title': indices.total, 'context': 'light'},
                                    'body': 'force_merge_note'|trans,
                                    'href': path('indices_force_merge_all', app.request.query.all),
                                }) }}
                            {% endif %}
                        {% endif %}

                        {% if is_granted('INDICES_CACHE_CLEAR', 'index') %}
                            {{ appImport.buttonModal({
                                'id': 'IndicesCacheClearAll',
                                'title': 'cache_clear'|trans,
                                'badge': {'title': indices.total, 'context': 'light'},
                                'body': 'cache_clear_note'|trans,
                                'href': path('indices_cache_clear_all', app.request.query.all),
                            }) }}
                        {% endif %}

                        {% if is_granted('INDICES_FLUSH', 'index') %}
                            {{ appImport.buttonModal({
                                'id': 'IndicesFlushAll',
                                'title': 'flush'|trans,
                                'badge': {'title': indices.total, 'context': 'light'},
                                'body': 'flush_note'|trans,
                                'href': path('indices_flush_all', app.request.query.all),
                            }) }}
                        {% endif %}

                        {% if is_granted('INDICES_REFRESH', 'index') %}
                            {{ appImport.buttonModal({
                                'id': 'IndicesRefreshAll',
                                'title': 'refresh'|trans,
                                'badge': {'title': indices.total, 'context': 'light'},
                                'body': 'refresh_note'|trans,
                                'href': path('indices_refresh_all', app.request.query.all),
                            }) }}
                        {% endif %}
                    {% endblock %}
                {% endembed %}

                {{ appImport.paginator(indices) }}

                {% include 'Modules/index/index_list.html.twig' with {'indices': indices} %}

                {{ appImport.paginator(indices) }}
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}

{% block scripts %}
    {{ parent() }}

    <script type="text/javascript">
        var form = document.querySelector('form');
        var page = document.getElementById('page');

        form.addEventListener('submit', function(event) {
            page.value = 1;
        });
    </script>
{% endblock %}
